package iqiyi;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        first();
    }
    public static void first(){
        Scanner sc=new Scanner(System.in);
        String str=sc.next();
        int[] aNums=new int[]{str.charAt(0)-'0',str.charAt(1)-'0',str.charAt(2)-'0',str.charAt(3)-'0',str.charAt(4)-'0',str.charAt(5)-'0'};
        int  aSum=aNums[0]+aNums[1]+aNums[2];
        int  bSum=aNums[3]+aNums[4]+aNums[5];
        if(aSum==bSum){
            System.out.println(0);
        }else if(aSum>bSum){
            System.out.println(helper(new int[][]{{aNums[0],aNums[1],aNums[2]},{aNums[3],aNums[4],aNums[5]}},aSum-bSum));
        }else {
            System.out.println(helper(new int[][]{{aNums[3],aNums[4],aNums[5]},{aNums[0],aNums[1],aNums[2]}},bSum-aSum));
        }

    }
    private static int helper(int[][] numV,int dif){
        Arrays.sort(numV[0]);
        Arrays.sort(numV[1]);
        if(dif <= numV[0][2] || dif + numV[1][0] <= 9)
            return  1;
        else if(dif <= numV[0][1] + numV[0][2] || dif + numV[1][0] + numV[1][1] <= 18
                || numV[0][2] + 9 - numV[1][0] >= dif)
            return 2;
        else
            return 3;
    }
}
